#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
    pid_t pid = fork();
    if(pid==0)
    {
        //子进程
        int cnt = 5;
        while(cnt--)
        {
            sleep(1);
            printf("子进程pid:%d\n",getpid());
        }
        exit(1);
    }
    //pid_t ret = wait(NULL);
    int status;
    pid_t ret = waitpid(-1,&status,0);
    printf("等待的子进程pid:%d,status:%d,exit code:%d,signal code:%d\n",ret,status,(status>>8)&0xFF,status&0x7F);
    return 0;
}
